package cn.ycxy.lbl.common.exception;

import cn.ycxy.lbl.common.exception.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author BaoL
 * @Date 2023/3/11 20:52
 * @Description 自定义运行异常类
 * @Since version-1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BusinessException extends RuntimeException {

    /**
     * 错误码
     */
    private Integer code;
    /**
     * 错误消息
     */
    private String message;

    /**
     *
     * @param code  错误码
     * @param message   错误消息
     * @param cause 原始异常对象
     */
    public BusinessException(Integer code, String message, Throwable cause){
        super(cause);
        this.code = code;
        this.message = message;
    }

    /**
     *
     * @param re  接收枚举类型
     */
    public BusinessException(ResponseEnum re){
        this.code = re.getCode();
        this.message = re.getMessage();
    }

    /**
     *
     * @param re  接收枚举类型
     * @param cause  原始异常对象
     */
    public BusinessException(ResponseEnum re, Throwable cause){
        this.code = re.getCode();
        this.message = re.getMessage();
    }

}
